from django.db import models

# Create your models here.
from django.db import models

# Create your models here.

#

from mlh.utils.models import BaseModel


class Channels(BaseModel):
    """新闻分类表"""
    name = models.CharField(max_length=50, verbose_name='分类名称')
    order = models.IntegerField(verbose_name='排序')

    class Meta:
        db_table = 'tb_channels'
        verbose_name = '新闻分类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class News(BaseModel):
    """新闻表"""
    title = models.CharField(max_length=30, verbose_name="新闻标题")
    user = models.ForeignKey("users.User", verbose_name='发表新闻用户')
    news_content = models.TextField(null=True, verbose_name='新闻内容')
    channel = models.ForeignKey(Channels, verbose_name='分类')
    image = models.ImageField(upload_to='news_image', verbose_name='新闻头像链接', null=True)
    clicks = models.IntegerField(default=0, verbose_name='点击量')
    is_deleted = models.BooleanField(default=True, verbose_name='是否删除新闻')

    class Meta:
        db_table = 'tb_news'
        verbose_name = '新闻'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title


class Comments(BaseModel):
    """评论表"""
    user = models.ForeignKey('users.User', on_delete=models.CASCADE, verbose_name='评论用户')
    parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, verbose_name='父评论')
    content = models.TextField(null=True, verbose_name='评论内容')
    news = models.ForeignKey(News, on_delete=models.CASCADE, verbose_name='新闻')

    class Meta:
        db_table = 'tb_comments'
        verbose_name = '评论'
        verbose_name_plural = verbose_name


# class NewsLabels(BaseModel):
#     """新闻标签表"""
#     news = models. ForeignKey(News, on_delete=models.CASCADE, verbose_name='新闻')
#     news_label = models.ForeignKey('Labels', on_delete=models.CASCADE, verbose_name='新闻标签名称')
#
#     class Meta:
#         db_table = 'tb_new_lables'
#         verbose_name = '新闻标签'
#         verbose_name_plural = verbose_name

